// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Column.java

package FlyBird;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

// Referenced classes of package day07:
//			Bird

public class Column extends JPanel
{

	int x;
	int y;
	int width;
	int height;
	int distance;
	int gap;
	int min;
	int max;
	BufferedImage column;

	public Column(int n)
		throws IOException
	{
		column = ImageIO.read(getClass().getResource("/images/column.png"));
		distance = 245;
		gap = 144;
		width = column.getWidth();
		height = column.getHeight();
		min = 80 + gap / 2;
		max = 420 - gap / 2;
		x = 500 + (n - 1) * distance;
		Random r = new Random();
		y = min + r.nextInt(max) % ((max - min) + 1);
	}

	public void step()
	{
		x--;
		if (x + width / 2 <= 0)
		{
			x = 2 * distance - width / 2;
			Random r = new Random();
			y = min + r.nextInt(max) % ((max - min) + 1);
		}
	}

	public void paint(Graphics g)
	{
		super.paint(g);
		g.drawImage(column, x - width / 2, y - height / 2, width, height, null);
	}

	public boolean hit(Bird b)
	{
		if (b.x + b.width / 2 >= x - width / 2 && b.x - b.width / 2 <= x + width / 2)
			return b.y - b.height / 2 < y - gap / 2 || b.y + b.height / 2 > y + gap / 2;
		else
			return false;
	}

	public boolean hit1(Bird b)
	{
		int x1 = x - width / 2 - b.width / 2;
		int x2 = x + width / 2 + b.width / 2;
		int y1 = (y - gap / 2) + b.height / 2;
		int y2 = (y + gap / 2) - b.height / 2;
		if (b.x >= x1 && b.x <= x2 && (b.y <= y1 || b.y >= y2))
			return true;
		if (b.x == x2 + 1)
			b.key = b.key + 5;
		return false;
	}
}
